package com.qst.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qst.Service.AdminRoomService;
import com.qst.Vo.AdminRoomVo;
import com.qst.pojo.Admin;
import com.qst.pojo.Room;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @packageName:com.qst.controller
 * @className:AdminRoomController
 * @Description:
 * @author:zhangyu
 * @date 2021/6/20 22:25
 **/

@Controller
public class AdminRoomController {

    @Resource
    AdminRoomService adminRoomService;

    @RequestMapping(value = "/adminroom")
    @ResponseBody
    public Map<String, Object> adminroom(AdminRoomVo adminRoomVo){
        PageHelper.startPage(adminRoomVo.getPage(),adminRoomVo.getLimit());
        List<Room> rooms = adminRoomService.adminallroom(adminRoomVo);
        Map<String, Object> map = new HashMap<String, Object>();
        PageInfo<Room> pageInfo = new PageInfo<Room>(rooms);
        map.put("code", 0);
        map.put("msg", "查询成功");
        map.put("count", pageInfo.getTotal());
        map.put("data", pageInfo.getList());
        return map;
    }

    @RequestMapping(value = "/adminfindroombyname")
    @ResponseBody
    public List<Room> adminfindroom(String roomname){
        List<Room> rooms = adminRoomService.adminfindbyname(roomname);
        return rooms;
    }

    @RequestMapping(value = "/addadminroom")
    @ResponseBody
    public Map<String,Object> addadminroom(Room room){
        Map<String,Object> map = new HashMap<String, Object>();
        if(adminRoomService.addadminroom(room)>0){
            map.put("success",true);
            map.put("message","添加成功");
        }else{
            map.put("success",false);
            map.put("message","添加失败");
        }
        return map;


    }
    @RequestMapping(value = "/updateadminroom")
    @ResponseBody
    public Map<String,Object> updateadminroom(Room room){
        Map<String,Object> map = new HashMap<String, Object>();
        if(adminRoomService.updateadminroom(room)>0){
            map.put("success",true);
            map.put("message","修改成功");
        }else{
            map.put("success",false);
            map.put("message","修改失败");
        }
        return map;


    }
    @RequestMapping(value = "/deleteadminroom")
    @ResponseBody
    public Map<String,Object> deleteadminroom(int id) {
        Map<String, Object> map = new HashMap<String, Object>();
        if (adminRoomService.deleteadminroom(id) > 0) {
            map.put("success", true);
            map.put("message", "删除成功");
        } else {
            map.put("success", false);
            map.put("message", "删除失败");
        }
        return map;
    }


}
